package database

import (
	"heartbeat/utils"
	"log"

	"github.com/go-redis/redis"
)

var redisClient *redis.Client

func InitRedisClient() error {
	config := utils.GetConfig()
	redisClient = redis.NewClient(&redis.Options{
		Addr:     config.Redis.Address,
		Password: config.Redis.Password, // no password set
		DB:       0,                     // use default DB
	})
	_, err := redisClient.Ping().Result()
	if err == nil {
		log.Println("Redis连接成功")
		return nil
	} else {
		log.Fatalln("Redis连接失败")
		return err
	}
}

func GetRedisClient() *redis.Client {
	return redisClient
}
